﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web.Mvc;
using GuRenFang.Service.Entity;
using GuRenFang.Service.IBiz;

namespace GuRenFang.Controllers.WebSite
{
    [ErrorHanderFilter]
    public class PackagesController : Controller
    {
        private readonly IPackagesBiz _packagesService;

        public PackagesController(IPackagesBiz packagesService)
        {
            _packagesService = packagesService;
        }


        public ActionResult List(int? page = 1)
        {
            short size = Convert.ToInt16(ConfigurationManager.AppSettings["pageSize"]);

            int totalRecord = 0;
            IEnumerable<Packages> packages = _packagesService.GetPackagesByPages(out totalRecord,
                                                                                 pageIndex: page.GetValueOrDefault(),
                                                                                 pageSize: size, orderFiled: "");

            var item = new PageItem
                           {
                               CurrentPage = page.GetValueOrDefault(),
                               TotalRecords = totalRecord,
                               TotalPages = (totalRecord%size == 0) ? totalRecord/size : totalRecord/size + 1,
                               ControllerName = "Packages",
                               ActionName = "List"
                           };

            var viewModels = new Pager<Packages> {DataSource = packages, Item = item};

            return View(viewModels);
        }
    }
}

